package servlet;

import java.io.IOException;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;


import service.BookService;
import vo.BookBean;

public class booklistservlet extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		   resp.setContentType("application/json;charset=utf-8");
		   PrintWriter w = resp.getWriter();
		 String val=req.getParameter("v");

           JSONObject j=new JSONObject();
           BookService list=new BookService();
		   if(val!=null){
			   String aa=val.substring(1,2);
				 int a=Integer.parseInt(aa);
				 List<Object> book =list.getall((a-1)*8,8);
				 j.put("aa", book);
		   }else{
              List<Object> book =list.getall(0,8);
              j.put("aa", book);}
			  List<String[]> ys = list.allcount();
			  List l=new ArrayList();
			    String s = ys.get(0)[0];
			    int v=Integer.parseInt(s);
			    int b=(v-1)/8+1;
			    for(int i=1;i<=b;i++){
			    	l.add(i);
			    }
			    j.put("ys", l);
			    
            
			w.write(j.toString());
			w.close();
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}}
